<template>
	<view class="body">
		<xk-header title="保养确认"></xk-header>
		<view class="list" >
			<view class="list-item header" @click="more = !more">
				<view>保养单号:  {{data.maintain_no}}</view>
				<image v-if="!more" src="/static/up.png"></image>
				<image v-else  src="/static/down.png"></image>
			</view>
			<view v-if="more" class="data-item">
				<view class="order-info">
					<view class="info-item"><view class="key">设备信息：</view>{{data.device_code}}-{{data.device_name}}</view>
					<view class="info-item"><view class="key">保养事项：</view>{{data.standard_name}}</view>
					<view class="info-item"><view class="key">保养时段：</view>{{data.plan_start_date}}至{{data.plan_end_date}}</view>
					<view class="info-item"><view class="key">保养工时：</view>{{data.plan_partorls_time}}分钟</view>
				</view>
			</view>
		</view>

		<view class="list" >
			<view class="list-item header" @click="orderMore = !orderMore">
				<view>保养记录</view>
				<image v-if="!orderMore" src="/static/up.png"></image>
				<image v-else  src="/static/down.png"></image>
			</view>
			<view v-if="orderMore" class="data-item">
				<view class="order-info">
					<view class="info-item"><view class="key">保养人：</view>{{data.record_user_name}}</view>
					<view @click="viewDetail" class="info-item" style="justify-content: space-between;">
						<view class="key">保养明细：</view>
						<view style="display: flex; align-items: center;">
							<text class="right-title1" style="color: #2C72FF;">查看明细</text>
							<image mode="aspectFill" class="jiantou" src="/static/jiantou.png"/>
						</view>
					</view>
					<view v-if="data.maintain_remark" class="info-item"><view class="key">保养记录：</view>{{data.maintain_remark}}</view>
					<view class="info-item"><view class="key">完成时间：</view>{{data.finish_time}}</view>
					<view class="info-item"><view class="key">是否超时：</view>{{data.is_timeout == '1' ? '是' : '否'}}</view>
					<view v-if="data.maintain_image" class="info-item"><view class="key"></view>
						<image-list :pics="data.maintain_image"></image-list>
					</view>
					<view v-if="data.confirm_proposal" class="info-item"><view class="key">确认意见：</view><text>{{data.confirm_proposal}}</text></view>
					<view v-if="data.check_result" class="info-item"><view class="key">抽查意见：</view><text>{{data.check_result}}</text></view>
				</view>
			</view>
		</view>

		<view class="list">
			<view class="list-item header">
				<view>保养确认</view>
			</view>
			<view>
				<view class="list-item textarea">
					<view>确认意见：</view>
					<textarea v-model="formData.confirm_proposal" placeholder="请输入确认意见" placeholder-class="placeholder"/>
				</view>
				<view class="list-item textarea">
					<view>备注：</view>
					<textarea v-model="formData.confirm_remark" placeholder="备注" placeholder-class="placeholder"/>
				</view>
			</view>
		</view>
		<view class="common-bottom-view">
			<view class="common-btn btn-plant" @click="doneConfirm('20')">退回</view>
			<view class="common-btn" @click="doneConfirm('10')">通过</view>
		</view>
		<view class="common-zw"></view>


	</view>
</template>

<script>
	import moment from 'moment'
	export default {
		data() {
			return {
				maintainId: '',
				data: {},
				more: true,
				orderMore: true,
				formData: {
					maintain_id: '',
					confirm_proposal: '',
					confirm_remark: '',
					isSubmit: true
				}
			};
		},
		onLoad(options) {
			this.maintainId = options.maintainId
			this.formData.maintain_id = this.maintainId
			this.getData();
		},
		methods:{
			viewDetail(){
				uni.navigateTo({
					url: '/pagesA/facility-upkeep/facility-upkeep-result-detail?dets=' + JSON.stringify(this.data.dets)
				})
			},
			getData(){
				this.$api.baseData_getPdMaintainTask(this.maintainId).then((res)=>{
					this.data = res.task
				})
			},
			doneConfirm(result){
				this.formData.confirm_result = result;
				if(result == '20' && !this.formData.confirm_proposal){
					this.$util.alert({
						content: "退回操作需填写确认意见",
					})
					return
				}
				this.$util.confirm({
					content: result == '20' ? '确定退回保养记录？' : '确定提交确认记录？',
					confirmText: "确定"
				}).then(isConfirm => {
					if (isConfirm) {
						this.$util.post({
							url: "app/pdMaintainTask/confirm",
							data: this.formData
						}).then(res => {
							uni.$emit('refreshHomeDataList')
							uni.$emit('refreshMaintainTask')
							uni.redirectTo({
								url: '/pagesA/facility-upkeep/facility-upkeep-finish?type=confirm'
							})
						})

					}
				})

			}
		}
	}
</script>

<style lang="scss" scoped>
@import '@/common/from.scss';
</style>
